global.cdn = "";
global.config = "server";
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const basics = require('./webpack.config.basic.js');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');

module.exports = merge(basics, {
    // 模式
    mode: 'development',
    // webpack server
    devServer: {
        // 添加白名单服务
        allowedHosts: [],
        // 响应都需要被替代为 index.html
        historyApiFallback: {
            rewrites: [{
                from: /^\/$/,
                to: "/dist/html/index.html"
            }, {
                from: /^\/business\/pages/,
                to: "/dist/html/index.html"
            }, {
                from: /^\/account\/login/,
                to: "/dist/html/index.html"
            }]
        },
        // 请求转发配置
        proxy: {
            '/mockapi': {
                changeOrigin: true,
                target: '',
                pathRewrite: { '^/mockapi': '' },
                bypass: function (req, res, proxyOptions) {
                    if (req.headers.accept && req.headers.accept.indexOf('html') !== -1) {
                        console.log('Skipping proxy for browser request.');
                        return '/dist/html/index.html';
                    }
                }
            },
            onProxyReq(req) {
                console.log('MOCK:', req.method, req.path);
            }
        },
        // 告诉服务器从哪里提供内容。
        contentBase: path.join(__dirname, "."),
        // 将用于确定应该从哪里提供 bundle
        publicPath: "/dist",
        // 实时刷新
        inline: true,
        // 端口
        port: 8008,
        //告诉dev-server在服务器启动后打开浏览器。将其设置true为打开默认浏览器。
        open: true,
        //指定打开浏览器时导航到的页面。
        openPage: "",
        //域名
        host: "project.com"
    },

    // 配置 mockd 配置
    resolve: {
        alias: {
            // 'port': path.join(__dirname, '.', 'mock'),
            'port': path.join(__dirname, '.', 'common', 'mock'),
        }
    },

    // 模块(Module)，决定了如何处理项目中的不同类型的模块
    module: {
        rules: [{
            //指定 loader 种类,可能的值有："pre" | "post"
            enforce: 'pre',
            test: /\.(js|jsx)$/,
            exclude: /node_modules\/|plugins\//,
            use: [{
                loader: "eslint-loader",
                options: {
                    fix: true,
                    emitWarning: true
                }
            }]
        }]
    },

    // 插件
    plugins: [
        new CaseSensitivePathsPlugin(),

        // 设置图片资源cdn
        new webpack.DefinePlugin({
            assets_cdn:JSON.stringify("")
        }),
    ],
    // 统计信息
    stats: {
        env: true,
        chunks: false,
        modules: false
    }
});